package arraylist;

import java.util.ArrayList;
import java.util.Iterator;
/*
* ArrayList遍历(迭代)方法:
*   1.迭代器遍历
*   2.特有遍历方法:索引遍历
*   3.增强for
* */
public class ArrayListDemo03 {
    public static void main(String[] args) {
        //method01();
        //method02();
        //method03();
    }

    private static void method03() {
        //3.增强for
        ArrayList<String> al = new ArrayList<>();
        al.add("abc");
        al.add("love");
        al.add("ghk");
        for (String s : al) {
            System.out.println(s);
        }
    }

    private static void method02() {
        //2.索引遍历
        ArrayList<String> al = new ArrayList<>();
        al.add("abc");
        al.add("love");
        al.add("ghk");
        for (int i = 0; i < al.size(); i++) {
            System.out.println(al.get(i));
        }
    }

    private static void method01() {
        //1.迭代器遍历
        ArrayList<String> al = new ArrayList<>();
        al.add("abc");
        al.add("love");
        al.add("ghk");
        Iterator<String> iterator = al.iterator();
        for (; iterator.hasNext(); ) {
            System.out.println(iterator.next());
        }
    }
}
